# Set working direction to the current file location
# Make sure sourcedata.zip is extracted
# load helper functions

cat("Create folder in parent directory to store tables")
dir.create("../tables")

cat("Create folder in parent directory to store figure")
dir.create("../graphs")

source("helper_functions.R")

#load packages
require(foreign)
require(lubridate)
require(countrycode)
require(pscl)
require(zoo)
require(ggplot2)
require(Matching)
require(gridExtra)
require(lme4)
require(splines)
require(reshape2)
require(xtable)
require(grid)
require(scales)
require(ordinal)
require(lmtest)
require(plm)
require(systemfit)
require(mediation)
require(mnormt)

######################################################################## Level 2 replication: re-process data files; to proceed,
# extract archive "Data.zip" and the archive located therein "sourcedata.zip"
# Otherwise proceed to Level 1 replication below
######################################################################

source("Data/annual_process.R") # Economic and political data
source("Data/nelda_process.R") # NELDA: estimate latent manipulation scores
source("Data/lambda_process.R") # Compute Coup Risk variable lambda
source("Data/mergeall.R")  # Merge into master data file
# Data preparation completed

#######################################################################
# Level 1 replication: Analyses
######################################################################

# Replicates Table 2, Figures 3,4,6 and Table A.1 (Appendix)
source("analysis.R")

# Replicates Figure 5.
source("matching.R")

# Replicates Figure and tables from 
source("robustness.R")

# IV analyses
source("IVanalysis.R")

# Endogeneous election-timing
source("selection.R")

# Non-monotonicity
source("nonlinear.R")

# Mediation analyses
source("mediation.R")

